﻿@using OA.Core.Model;
@using OA.Model;
@{
    Layout = null;
    BaseConfig config = ViewBag.BaseConfig;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>@ViewBag.Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="@config.OssUrl/front/css/admin.css" />
    <link rel="stylesheet" href="@config.OssUrl/admin/layuiadmin/layui/css/layui.css">
    <script type="text/javascript" src="@config.OssUrl/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="@config.OssUrl/admin/layuiadmin/layui/layui.js"></script>
    <script type="text/javascript">
        var parentUrl = "";
        var currentUrl = "";
        var ossSignatureUrl =  window.location.protocol + "//" + window.location.host+ "/Home/GetOssSignature?Signature=@ViewBag.Signature";
    </script>
</head>
<body>
    <div class="fly-panel-user" style="padding:6px">
        @RenderBody()
    </div>
    <script type="text/javascript">
        var form;
        function InintCotrol() {
            var dateCotrol = $(".mydate");
            if (dateCotrol.length > 0) {
                $.each(dateCotrol, function () {
                    var controlID = $(this).prop("id");
                    var type = $(this).attr("data-type");
                    if (controlID != undefined && controlID != null) {
                        laydate.render({
                            elem: '#' + controlID,
                            type: type
                        });
                    }
                });
            }
            var autocompleteCotrol = $(".autocomplete");
            if (autocompleteCotrol.length > 0) {
                $.each(autocompleteCotrol, function () {
                    var controlID = $(this).prop("id");
                    var url = $(this).attr("data-url");
                    var type = $(this).attr("data-type");
                    var name = $(this).attr("data-name");
                    if (controlID != undefined && controlID != null) {
                        if (type == 1) {
                            autocomplete.render({
                                elem: '#' + controlID,
                                url: url,
                                cache: false,
                                template_val: '{{d.JsonInfo}}',
                                template_txt: '{{d.Name}}'
                            });
                        }
                        else if (type == 2) {
                            autocomplete.render({
                                elem: '#' + controlID,
                                url: url,
                                cache: false,
                                template_val: '{ID:d.ID,Title:d.Name}',
                                template_txt: '{{d.Name}}',
                                onselect: function (resp) {
                                    $("#" + controlID).val("");
                                    var trLength = $("." + controlID + "Table tbody").find("tr").length;
                                    var indexStep = parseInt(trLength);
                                    var nowRow = '<tr><td>' + resp.ID + '<input type="hidden" class="ID" value="' + resp.ID + '" name="' + name + '[' + trLength + '].ID" /><input type ="hidden" class="Title" value="' + resp.Title + '" name="' + name + '[' + trLength + '].Title" /><input type ="hidden" class="Status" value="1" name="' + name + '[' + trLength + '].Status" /></td><td>' + resp.Title + '</td><td><span class="delete">删除</span></td></tr>';
                                    $("." + controlID + "Table tbody").append(nowRow);
                                }
                            });
                        }
                        else if (type == 3) {
                            autocomplete.render({
                                elem: '#' + controlID,
                                url: url,
                                cache: false,
                                template_val: '{p:"{d.p}}",s:"{d.s}}",i:"{d.i}}",n:"{d.n}}",d:"{d.d}}",}',
                                template_txt: '{{d.n}} <span class=\'layui-badge layui-bg-gray\'>{{d.d}}&nbsp;{{d.s}}&nbsp;{{d.n}}</span>',
                                onselect: function (resp) {
                                    $("#" + controlID).val("");
                                    var trLength = $("." + controlID + "Table tbody").find("tr").length;
                                    var indexStep = parseInt(trLength) + 1;
                                    if ($("." + name + "_" + resp.i).length > 0) return;
                                    $("." + controlID + "Table tbody").append('<tr  data-id="' + trLength + '" class="' + name + '_' + resp.i + '"><td><input type="hidden" class="Status" value="1" name="' + name + '[' + trLength + '].Status"/><input type="hidden" value="' + resp.p + '" name="' + name + '[' + trLength + '].PositionID" />' + resp.d + '</td><td><input type="hidden" value="' + resp.i + '" name="' + name + '[' + trLength + '].EmpID"/>' + resp.s + '</td><td>' + resp.n + '</td><td><span class="delete">删除</span></td></tr>');
                                }
                            });

                        }
                        else if (type == 4) {
                            autocomplete.render({
                                elem: '#' + controlID,
                                url: url,
                                cache: false,
                                template_val: '{p:"{d.p}}",s:"{d.s}}",i:"{d.i}}",n:"{d.n}}",d:"{d.d}}",}',
                                template_txt: '{{d.n}} <span class=\'layui-badge layui-bg-gray\'>{{d.d}}&nbsp;{{d.s}}&nbsp;{{d.n}}</span>',
                                onselect: function (resp) {
                                    $("#" + controlID).val("");
                                    var trLength = $("." + controlID + "Table tbody").find("tr").length;
                                    var indexStep = parseInt(trLength) + 1;
                                    if ($("." + name + "_" + resp.i).length > 0) return;
                                    $("." + controlID + "Table tbody").append('<tr  data-id="' + trLength + '" class="' + name + '_' + resp.i + '"><td><input type="hidden" class="Status" value="1" name="' + name + '[' + trLength + '].Status"/><input type="hidden" value="' + resp.p + '" name="' + name + '[' + trLength + '].PositionID" />' + resp.d + '</td><td><input type="hidden" value="' + resp.i + '" name="' + name + '[' + trLength + '].EmpID"/>' + resp.s + '</td><td>' + resp.n + '</td><td><input type="text" class="layui-input" style="max-width:80px;" value="' + indexStep + '" name="' + name + '[' + trLength + '].Setp"/></td><td><span class="delete">删除</span></td></tr>');
                                }
                            });

                        }

                    }
                });
            }
        }
        layui.use(['form', 'layedit', 'element', 'laydate','autocomplete'], function () {
            form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , element = layui.element
                ,autocomplete = layui.autocomplete;

            InintCotrol();

            
           
            //监听提交
            form.on('submit(OAForm)', function (data) {
                $(".mySubmit").prop("disabled", true);
                var index = layer.load(1, {
                    shade: [0.1, '#fff']
                });
                var myFrom = $("#myForm");
                $.post(myFrom.prop("action"), myFrom.serialize(), function (result) {
                    $(".mySubmit").prop("disabled", false);
                    layer.closeAll();
                    if (result.State == 400) {
                        layer.msg(result.Msg);
                        return;
                    }
                    if (result.State == 402) {
                        layer.msg(result.Msg);
                        return;
                    }
                    else {
                        if (result.Msg.startsWith("url:")) {
                            window.location.href = result.Msg.substring(4);
                        }
                        else {
                            layer.msg(result.Msg);
                            if (parentUrl != "") {
                                setTimeout(function () { window.parent.href = parentUrl; }, 1000);
                            }
                            else if (currentUrl != "") {
                                window.location.href = currentUrl;
                            }
                            else {
                                window.parent.RefreshResultList();
                            }
                        }

                    }
                });
                return false;
            });
        });


    </script>
</body>
</html>